const express = require("express");
const router = require('./router')
const fs = require("fs")//文件解析插件
const https = require("https")//https
const bodyParser = require('body-parser')// post 请求body 插件
const cors = require("cors")//解决跨越的差件

const app = express();


app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }))

app.use(bodyParser.json())

app.use('/',router)



const privateKey =  fs.readFileSync('./https/5324067_www.huijiaoe.com.key');
const pem =  fs.readFileSync('./https/5324067_www.huijiaoe.com.pem');

const credentials = {
    key:privateKey,
    cret:pem
}

const httpsServer = https.createServer(credentials,app)


const server = app.listen(5000,function(){
    const {addrss , port } = server.address();
    console.log("服务启动成功","地址为",addrss ,"port为",port);
})


const serverIo =  app.listen(5002)
var io = require('socket.io').listen(serverIo);


require('./model/socket')(io);



httpsServer.listen(18082,function(){
    console.log('HTTPS Server is running on:https://localhost:%s',18082)
})